package com.zxx.pattern.chainPattern.chain3;

/**
 * 抽象处理者
 *
 * @author zxx on 2021/2/22
 */
public abstract class AbstractHandler {

    protected AbstractHandler nextHandler;  //下一个节点处理者对象


    /**
     * 处理请求
     *
     * @param request 请求对象（跟级别有关）
     */
    public final void handleRequest(AbstractRequest request) {
        //判断当前处理者的级别 是否与 请求者级别 一致
        if (getHandlerLevel() == request.getRequestLevel()) {
            handle(request);
        } else {
            if (nextHandler != null) {
                nextHandler.handleRequest(request);
            } else {
                System.out.println("不能处理请求");
            }
        }

    }

    protected abstract void handle(AbstractRequest request);

    protected abstract int getHandlerLevel();


}
